WPF application will hangs when run in the sNativeDigits damaged device · Issue #7658 · dotnet/wpf · GitHub

您所在的位置:网站首页 wpf frameworkelement WPF application will hangs when run in the sNativeDigits damaged device · Issue #7658 · dotnet/wpf · GitHub

WPF application will hangs when run in the sNativeDigits damaged device · Issue #7658 · dotnet/wpf · GitHub

2023-03-23 12:00| 来源: 网络整理| 查看: 265

Description

The TextBlock will throw the IndexOutOfRangeException in TextBlock.MeasureOverride. The exception stack is:

> PresentationCore.dll!MS.Internal.TextFormatting.DigitState.HasLatinDigits(System.Globalization.CultureInfo culture) PresentationCore.dll!MS.Internal.TextFormatting.DigitState.GetDigitCulture(System.Globalization.CultureInfo numberCulture, System.Windows.Media.NumberSubstitutionMethod method, out bool contextual) PresentationCore.dll!MS.Internal.TextFormatting.DigitState.SetTextRunProperties(System.Windows.Media.TextFormatting.TextRunProperties properties) PresentationCore.dll!MS.Internal.TextFormatting.SimpleRun.Create(MS.Internal.TextFormatting.FormatSettings settings, System.Windows.Media.TextFormatting.CharacterBufferRange charString, System.Windows.Media.TextFormatting.TextRun textRun, int cp, int cpFirst, int runLength, int widthLeft, int idealRunOffsetUnRounded, double pixelsPerDip) PresentationCore.dll!MS.Internal.TextFormatting.SimpleTextLine.Create(MS.Internal.TextFormatting.FormatSettings settings, int cpFirst, int paragraphWidth, double pixelsPerDip) PresentationCore.dll!MS.Internal.TextFormatting.TextFormatterImp.FormatLineInternal(System.Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, int lineLength, double paragraphWidth, System.Windows.Media.TextFormatting.TextParagraphProperties paragraphProperties, System.Windows.Media.TextFormatting.TextLineBreak previousLineBreak, System.Windows.Media.TextFormatting.TextRunCache textRunCache) PresentationCore.dll!MS.Internal.TextFormatting.TextFormatterImp.FormatLine(System.Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, double paragraphWidth, System.Windows.Media.TextFormatting.TextParagraphProperties paragraphProperties, System.Windows.Media.TextFormatting.TextLineBreak previousLineBreak, System.Windows.Media.TextFormatting.TextRunCache textRunCache) PresentationFramework.dll!System.Windows.Controls.TextBlock.MeasureOverride(System.Windows.Size constraint) PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) PresentationFramework.dll!System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size constraint) PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) PresentationFramework.dll!MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement element, System.Windows.Size constraint) PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) PresentationFramework.dll!System.Windows.Controls.Decorator.MeasureOverride(System.Windows.Size constraint) PresentationFramework.dll!System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size constraint) PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) PresentationFramework.dll!System.Windows.Controls.Border.MeasureOverride(System.Windows.Size constraint) PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) PresentationFramework.dll!System.Windows.Window.MeasureOverrideHelper(System.Windows.Size constraint) PresentationFramework.dll!System.Windows.Window.MeasureOverride(System.Windows.Size availableSize) PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize) PresentationCore.dll!System.Windows.UIElement.Measure(System.Windows.Size availableSize) PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize() PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisualInternal.set(System.Windows.Media.Visual value) PresentationFramework.dll!System.Windows.Window.SetRootVisualAndUpdateSTC() PresentationFramework.dll!System.Windows.Window.SetupInitialState(double requestedTop, double requestedLeft, double requestedWidth, double requestedHeight) PresentationFramework.dll!System.Windows.Window.CreateSourceWindow(bool duringShow) PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox) WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled) WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled) WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(nint hwnd, int msg, nint wParam, nint lParam)

For more info, see dotnet/runtime#83764

Reproduction Steps Add the TextBlock in MainWindow: Run the application in the device which with the damaged settings Expected behavior

Work well. The application can show the TextBlock

Actual behavior

Throw the exception

Regression?

.NET 5

Known Workarounds

This is the dotnet runtime and wpf issues. As the dotnet/runtime#83764 , the CultureInfo.NumberFormat may throw IndexOutOfRangeException in dotnet runtime. And the wpf will use culture.NumberFormat.NativeDigits in HasLatinDigits, see

wpf/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/NumberSubstitution.cs

Lines 213 to 223 in 6f56d3f

private static bool HasLatinDigits(CultureInfo culture) { string[] digits = culture.NumberFormat.NativeDigits; for (int i = 0; i > PresentationCore.dll!System.Windows.Markup.XmlLanguage.GetSpecificCulture() PresentationFramework.dll!MS.Internal.Text.DynamicPropertyReader.GetCultureInfo(System.Windows.DependencyObject element) PresentationFramework.dll!MS.Internal.Text.TextProperties.InitCommon(System.Windows.DependencyObject target) PresentationFramework.dll!MS.Internal.Text.TextProperties.TextProperties(System.Windows.FrameworkElement target, bool isTypographyDefaultValue) PresentationFramework.dll!System.Windows.Controls.TextBlock.GetLineProperties() PresentationFramework.dll!System.Windows.Controls.TextBlock.EnsureTextBlockCache() PresentationFramework.dll!System.Windows.Controls.TextBlock.MeasureOverride(System.Windows.Size constraint)

The XmlLanguage.GetSpecificCulture will call the CultureInfo.GetCultureInfoByIetfLanguageTag to get the CultureInfo. And the CultureInfo.GetCultureInfoByIetfLanguageTag will use the user override.

That is why wpf be affected by dotnet/runtime#83764 and that is why we can not use new CultureInfo("en-US", false).NumberFormat to fix this. In other words, the wpf framework will call the CultureInfo.GetCultureInfoByIetfLanguageTag and we should not change it to new CultureInfo(xx, false). And I think the client application use the user settings is reasonable behavior. And the application can handle error device settings.

Impact

No response

Configuration

No response

Other information

No response



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3